package com.matt.swagger2;

import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
//@Profile({"dev"})
public class Swagger2Config {

	@Bean
    public Docket createRestApiWeb() {
    	Predicate<RequestHandler> selector1 = RequestHandlerSelectors.basePackage("com.matt.controller");
        Predicate<RequestHandler> selector2 = RequestHandlerSelectors.basePackage("com.dotflat");

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo("客户关系管理"))
                .groupName("客户关系管理")
                .select()
                .apis(Predicates.or(selector1,selector2))
                .paths(PathSelectors.any()) //过滤的接口
                .build();
    }

    private ApiInfo apiInfo(String name) {
        return new ApiInfoBuilder()
                .title("小象湾托育系统接口 - " + name) //大标题
                .description("")
                .termsOfServiceUrl("http://dotflat.cn/")
                .contact(new Contact("Ron","http://sigarron.dev", "luoying@tuo51.com"))
                .version("1.0")
                .build();
    }

}